Bug 8023541

Bug Description:

This is a race bug.
The expected exception is a NullpointerException.
More details about this bug are at JDK-8023541 JIRA page.

Interleaving Description:

sun.rmi.server.Activation$SystemRegistryImpl

t1  t2    SystemRegistryImpl(int port,
                                   RMIClientSocketFactory csf,
                                   RMIServerSocketFactory ssf,
                                   ActivationSystem systemStub)
                    throws RemoteException
                {
1                   super(port, csf, ssf);
3                   this.systemStub = systemStub;
                }
        
                
                public Remote lookup(String name)
                    throws RemoteException, NotBoundException
                {
                    if (name.equals(NAME)) {
    2                   return systemStub;
                    } else {
                        return super.lookup(name);
                    }
                }

a) thread 1 initiates a SystemRegistryImpl instance at 1.
b) context switched, thread 2 returns systemStub at 2. But systemStub is still not initiated yet, so it returns a null value which is not expected.
c) context switched, thread 1 initiates systemStub at 3.

How To Reprocuce:

There are two stages to reproduce this bug:

This bug is reproduced under JDK 1.7.0.
It started at JDK 1.7.0, and hae been fixed since JDK 1.9.0.
Execute the following scripts to run the test to reproduce the bug (assume the location of the jdk7 test project is jdk7_test_home).

Linux:
${jdk7_test_home}/scripts/8023541.sh [--javaloc path]
Windows:
%jdk7_test_home%\scripts\8023541.bat [--javaloc path]

Option Function
--javaloc The location of JDK that is eligible to reproduce the bug, if your java environment is not eligible.
In this case, it's JDK 1.7.0. It should be the absolute path to the JDK's java starter and ended with "/".
For example: ~/jdk/home/jdk1.7.0/bin/